#define _CRT_SECURE_NO_WARNINGS 1
struct ListNode* removeElements(struct ListNode* head, int val) {


    if (head == NULL)
        return NULL;
    struct ListNode* cur = head;
    struct ListNode* newnode, * tail;
    newnode = tail = NULL;
    while (cur)
    {
        if (cur->val != val)
        {


            if (tail == NULL)
            {
                newnode = tail = cur;
            }
            else
            {
                tail->next = cur;
                tail = tail->next;
            }
            cur = cur->next;
        }
        else
        {
            struct ListNode* next = cur->next;
            free(cur);

            cur = next;
        }
    }
    if (tail)
        tail->next = NULL;
    return newnode;
}